//
//  LGTRWZPersonCommonCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/9/2.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTRWZPersonServerCell: UITableViewCell {

    var bageView:UIImageView?
    var _model:Dictionary<String, Any>?
    var clickBlock:ClickIndexBlock?
    var model:Dictionary<String, Any>?{
        get{
            return _model
        }set{
            _model = newValue
            self.setData()
        }
    }
    
    func setData(){
//        let icon:String = self.model?["icon"] as? String ?? ""
//        self.iconImageView?.image = UIImage.init(named: icon)
//
//        let title:String = self.model?["title"] as? String ?? ""
//        self.titleLabel?.text = title
//
//        let isbage:Bool = self.model?["isbage"] as? Bool ?? false
//        self.bageView?.isHidden = !isbage
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle.none
       // self.accessoryType =  UITableViewCell.AccessoryType.disclosureIndicator
        self.contentView.backgroundColor = ViewBackColor
        
//        self.bageView = LGTViewCreateUtil.share.createImageViewCorner(corner: SizeFitFloat(4), imageName: "")
//        self.addSubview(self.bageView!)
//        self.bageView?.backgroundColor = UIColor.red
//        self.bageView!.snp.makeConstraints { (make) in
//            make.right.equalTo(SizeFitFloat(-44))
//            make.width.height.equalTo(SizeFitFloat(8))
//            make.centerY.equalTo(self.iconImageView!)
//        }
        
        let myMoneyView:UIImageView = LGTViewCreateUtil.share.createImageViewCorner(corner: SizeFitFloat(5))
        myMoneyView.backgroundColor = UIColor.white
        myMoneyView.isUserInteractionEnabled = true
        self.addSubview(myMoneyView)
        myMoneyView.snp.makeConstraints { (make) in
            make.height.equalTo(SizeFitFloat(121))
            make.top.equalTo(0)
            make.left.equalTo(SizeFitFloat(9))
            make.right.equalTo(SizeFitFloat(-9))
            make.bottom.equalTo(-SizeFit(9))
        }
        
        let myMoneyLabel:UILabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: 0, text: "我的服务")
        myMoneyLabel.font = KBFont(size: SizeFitFloat(15))
        myMoneyView.addSubview(myMoneyLabel)
        myMoneyLabel.snp.makeConstraints { (make) in
            make.height.equalTo(SizeFitFloat(16))
            make.left.equalTo(SizeFit(19))
            make.top.equalTo(SizeFitFloat(15))
        }

        let infoArray:Array<Dictionary<String, Any>> = [
            ["icon":"myweallet", "title":"我的钱包"],
            ["icon":"messagenotification", "title":"消息通知"],
            ["icon":"feedback", "title":"意见反馈"],
            ["icon":"setup", "title":"设置"],
        ]

        let count:Int = infoArray.count
        let itemW:CGFloat = (KScreenW - SizeFitFloat(18)) / CGFloat(count)
        let itemH = SizeFit(44)
        for i in 0..<count{
            let info:Dictionary<String, Any> = infoArray[i]
            let icon:String = info["icon"] as! String
            let title:String = info["title"] as! String

            let button:UIButton = UIButton.init()
            myMoneyView.addSubview(button)
            button.snp.makeConstraints { (make) in
                make.left.equalTo(CGFloat(i) * itemW)
                make.width.equalTo(itemW)
                make.height.equalTo(itemH)
                make.top.equalTo(SizeFitFloat(60))
            }

            let iconView:UIImageView = LGTViewCreateUtil.share.createImageView(image: icon)
            button.addSubview(iconView)
            iconView.snp.makeConstraints { (make) in
                make.centerX.equalTo(button)
                make.top.equalTo(0)
                make.width.height.equalTo(SizeFitFloat(16))
            }

            let label:UILabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: TextColor, fontSize: SizeFitFloat(12), text: title)
            button.addSubview(label)
            label.snp.makeConstraints { (make) in
                make.top.equalTo(SizeFitFloat(29))
                make.centerX.equalTo(button)
                make.height.equalTo(SizeFitFloat(12))
            }

            button.tag = i
            button.addTarget(self, action: #selector(gotoClickAction), for: UIControl.Event.touchUpInside)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    @objc func gotoClickAction(sender:UIView){
        if self.clickBlock != nil{
            self.clickBlock!(sender.tag)
        }
    }
}
